//
//  main.c
//  Wood
//
//  Created by Wayne on 9/10/14.
//  Copyright (c) 2014 Wayne. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include "Arch.h"
#include "Functions.h"

int main(int argc, const char *argv[]) {
    Frame *frame = malloc(sizeof(Frame));
    frame->variable = NULL;
    frame->functionDefinition = NULL;
    frame->parentFrame = NULL;
    Statement *stm1;
    ParameterList *parameter = malloc(sizeof(ParameterList));
    parameter->name = "a";
    parameter->next = malloc(sizeof(ParameterList));
    parameter->next->name = "b";
    parameter->next->next = NULL;
    Block *block;
    block = malloc(sizeof(Block));
    block->statementList = malloc(sizeof(StatementList));
    block->statementList->statement = createReturnStatement(createBinaryExpression(WdAddExpression, createIdentifierExpression("a"), createIdentifierExpression("b")));
    stm1 = createFunctionDefinitionStatement("plus", parameter, block);
    StatementList *statement = malloc(sizeof(StatementList));
    statement->statement = stm1;
    statement->next = NULL;
    executeStatementList(frame, statement);
    Expression *exp1, *exp2, *exp3, *exp4;
    exp1 = createAssignExpression("a", createStringExpression(createString("wood")));
    exp2 = createAssignExpression("b", createBinaryExpression(WdModExpression,
                                                              createDoubleExpression(5.4),
                                                              createIntExpression(2)));
    exp3 = createBinaryExpression(WdAddExpression, createIdentifierExpression("a"), createIdentifierExpression("b"));
    ArgumentList *argument = malloc(sizeof(ArgumentList));
    argument->expression = exp1;
    argument->next = malloc(sizeof(ArgumentList));
    argument->next->expression = exp2;
    argument->next->next = NULL;
    exp4 = createFunctionCallExpression("plus", argument);
    Value v = evalExpression(frame, exp4);
    printf("%s\n", v.u.stringValue->string);
    return 0;
}